import sys
import os

file_path = os.path.abspath(__file__)
end = file_path.index('qmt_auto_trade') + 17
project_path = file_path[0:end]
sys.path.append(project_path)


import config.config_service as config_service
import pandas as pd
import mk_common.component.push.wx_pusher_api as wx_pusher_api
import mk_common.component.push.email_pusher_api as email_pusher_api


def push_msg(title, msg):
    config_info_dict = config_service.get_config_info()
    wx_pusher_token = config_info_dict.get('wx_pusher_token')
    wx_pusher_uid = config_info_dict.get('wx_pusher_uid')

    token_df = pd.DataFrame([
        [wx_pusher_token, wx_pusher_uid]
    ], columns=['token', 'uids'])

    wx_pusher_api.push_msg_to_wechat(title, msg, token_df)
    config = {
        "sender_name": config_service.get_config_info().get('email_sender_name'),
        "sender_email": config_service.get_config_info().get('sender_email'),  # 发送信息邮箱
        "password": config_service.get_config_info().get('email_token'),  # 在邮箱设置中获取SMTP授权码
        "receiver_emails": config_service.get_config_info().get('receiver_emails'),  # 接受信息邮箱
        "smtp_server": config_service.get_config_info().get('smtp_server'),
        "smtp_port": int(config_service.get_config_info().get('smtp_port'))
    }

    # 示例1：发送纯文本邮件
    result, message = email_pusher_api.send_email(
        **config,
        subject=title,
        content=msg
    )
    return result


if __name__ == '__main__':
    push_msg('test', 'test_msg')
